<template lang="html">
  <div>
    <div class="search">
        <div class="input">
            <p>
				<label>应用名称:</label>
				<el-input v-model="searchData.appName"  placeholder="请输入应用名称"></el-input>
                <label>是否强制更新:</label>
				<el-select  placeholder="请输入是否强制更新" v-model="searchData.isForce">
						<el-option value="">请选择</el-option>
						<el-option value="Y" label="是">是</el-option>
                        <el-option value="N" label="否">否</el-option>

				</el-select>
                <label>客户端类型:</label>
				<el-select  placeholder="请输入客户端类型" v-model="searchData.clientType">
						<el-option value="">请选择</el-option>
						<el-option value="ANDORID" label="安卓">安卓</el-option>
                        <el-option value="IOS" label="IOS">IOS</el-option>
				</el-select>

			</p>

            <!-- <p><label>来源名称：</label><el-input placeholder="请输入编码" label="条件"></el-input></p>
            <p><label>来源编码：</label><el-input placeholder="请输入编码" label="条件"></el-input></p>
            <p><label>来源ID：</label><el-input placeholder="请输入编码" label="条件"></el-input></p> -->
            <p><el-button type="primary" class="se" @click="searchOrder()" style="margin-left:10px;">搜索</el-button></p>
        </div>
    </div>
    <div class="add">
       <el-button type="primary" @click="add">新增</el-button>
    </div>
    <tableVue :list="list" :state="false" @sizeChange="handleSize" :total="total" v-loading='loading'>
        <slot>
          <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  @click="handleEdit(scope.$index, scope.row)">编辑
                </el-button>
                <el-button
                  size="mini"
                  type="success"
                  class="del"
                  @click="handleDetails(scope.$index, scope.row)">详情</el-button>
                   <el-button
                  size="mini"
                  type="danger"
                  class="del"
                  @click="handleDel(scope.$index, scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </slot>
    </tableVue>
    <el-dialog
      title="提示"
      :visible.sync="dialog"
      width="80%">
      <el-form :model="addData" ref="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm">
          <el-form-item label="应用名称：" prop="appName">
              <el-input v-model="addData.appName" placeholder="请输入应用名称"></el-input>
          </el-form-item>
          <el-form-item label="客户端类型：" prop="clientType">
              <el-select v-model="addData.clientType" placeholder="请选择客户端类型">
                  <el-option value="ANDROID" label="安卓">安卓</el-option>
                  <el-option value="IOS" label="IOS">IOS</el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="版本号：" prop="version">
                <el-input v-model="addData.version" placeholder="请输入版本号"></el-input>
          </el-form-item>
          <el-form-item label="版本编号：" prop="code">
                <el-input v-model="addData.code" placeholder="请输入版本编号"></el-input>
          </el-form-item>
          <el-form-item label="是否强制更新：" prop="isForce">
               <el-select  v-model="addData.isForce" placeholder="请选择是否强制更新">
                  <el-option value="Y" label="是">是</el-option>
                  <el-option value="N" label="否">否</el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="下载方式：" prop="downloadType">
              <el-select  v-model="addData.downloadType" placeholder="请选择下载方式">
                    <el-option :value="1" label="直接下载">直接下载</el-option>
                    <el-option :value="2" label="内部跳转">内部跳转</el-option>
                    <el-option :value="3" label="外部跳转">外部跳转</el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="URL地址：" prop="url">
              <el-input v-model="addData.url" placeholder="请输入url地址"></el-input>
          </el-form-item>
          <el-form-item label="版本更新说明：">
                    <EditorVue v-model="addData.description"/>
          </el-form-item>
          <el-form-item class="confirm">
              <el-button type="primary" @click="submitForm('ruleForm')">{{type=="1"?"创建":'更新'}}</el-button>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- <dialogVue title="新增工单信息" :dialog="dialog" @close="changeData" :state="false">
        <slot>

        </slot>
    </dialogVue> -->
  </div>
</template>

<script>
import Data from './applicationData.js'
import dialogVue from '@/components/dialog.vue'
import EditorVue from '@/components/Editor.vue'
import tableVue from '@/components/alltable.vue'
import {
  applicationList,appCheck,appChange,Delapp
} from "@/api/common/upImg";
export default {
  components : {
    tableVue,
    dialogVue,
    EditorVue
  },
   data () {
     return JSON.parse(JSON.stringify(Data))
   },
   mounted () {
	 this.getAppraiserAdminList();
   },
   methods : {
     getAppraiserAdminList (data) {
         this.loading =true;
       applicationList(data).then(res=>{
         console.log(res);
           if(res.data.code == "OK"){
               this.total = res.data.data.total;
               this.loading = false;
               this.list.tbody=res.data.data.records.map(res=>{
                   switch(res.downloadType){
                       case 1:
                          res['showdownloadType'] ="直接下载";
                          break;
                        case 2:
                            res['showdownloadType'] ="内部跳转";
                          break;
                        case 3:
                            res['showdownloadType'] ="外部跳转";
                          break;

                        default:
                            break;
                   }
                    switch(res.isForce){
                       case "Y":
                          res['showisForce'] ="是";
                          break;
                        case "N":
                            res['showisForce'] ="否";
                          break;
                        default:
                            break;
                   }
                   switch(res.clientType){
                       case "ANDROID":
                          res['showclientType'] ="安卓";
                          break;
                        case "IOS":
                            res['showclientType'] ="IOS";
                          break;
                        default:
                            break;
                   }
                   return res
               })
           }else{
               this.$message.error(res.data.message)
           }
        })
	 },
	 handleSize(size){
		  let data ={
			 current:size,
			 size:10
         }
         for (let i in this.searchData){
             if(this.searchData[i]){
                data[i] = this.searchData[i]
             }
         }
		 this.getAppraiserAdminList(data)
     },

     changeData (data) {
       this.dialog = data;
     },
     add () { //新增工单
        this.addData = {}
        this.$refs['ruleForm']&&this.$refs['ruleForm'].resetFields();
        this.dialog = true;
        this.type = 1;
	 },
	 searchOrder(){
         let data = {};
         for(let i in this.searchData){
             if(this.searchData[i]){
                 data[i] = this.searchData[i]
             }
         }
		 this.getAppraiserAdminList(data)
     },
     handleDel(index,data){//删除
        this.delMessage(()=>{
            let arr =[];
            arr.push(data.appId)
            Delapp(arr).then(res=>{
                if(res.data.code == "OK"){
                    this.getAppraiserAdminList();
                    this.$message.success('删除成功！')
                }else{
                    this.$message.error(res.data.code)
                }
            })
        })
     },
     handleDetails(index,data){//详情
        this.$router.push({name:'applicationDetails',query:{data}})
     },
     handleEdit(index,data){//编辑
        this.dialog = true;
        this.type = 2;
        this.$refs['ruleForm']&&this.$refs['ruleForm'].resetFields();
        console.log(data);
        for(let i in data){
            this.addData[i] = data[i]
        }
     },
     submitForm(formName){
        this.$refs[formName].validate((valid) => {
            if (valid) {
                if(this.type=="1"){
                    appChange(this.addData,"POST").then(res=>{
                        if(res.data.code == "OK"){
                            this.getAppraiserAdminList();
                            this.$message.success("新增成功！")
                            this.dialog =false;
                        }else{
                            this.$message.error(res.data.message)
                        }
                    })
                }else{
                    appChange(this.addData,"PUT").then(res=>{
                        if(res.data.code == "OK"){
                            this.$message.success('编辑成功！');
                            this.getAppraiserAdminList();
                              this.dialog =false;
                        }else{
                            this.$message.error(res.data.message)
                        }
                    })
                }
            }
        });
     }
   }
}
</script>

<style scoped>
  @import "../../../styles/common.css";
  .confirm {
    position: absolute;
    bottom: -1px;
    right: 100px;
  }
</style>
